//
//  HZGoodsDetailNaviBar.m
//  app
//
//  Created by 刘华舟 on 15/6/4.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZGoodsDetailNaviBar.h"

static const NSInteger kImageButtonWidth = 80;

@interface HZGoodsDetailNaviBar()

@property (strong, nonatomic) UIButton *backBtn;
@property (strong, nonatomic) UIButton *serviceBtn;

@end

@implementation HZGoodsDetailNaviBar

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [HZ_WHITE_COLOR colorWithAlphaComponent:0.0];
        
        //返回
        self.backBtn = [[UIButton alloc] initWithFrame:CGRectOf([self.ubo ux:kSizeMallViewMargin oy:20],
                                                                     [self.ubo ow:kImageButtonWidth/2 oh:kImageButtonWidth/2])];
        [self.backBtn setImage:[UIImage imageNamed:kImageMallArrowBackReturnRed] forState:UIControlStateNormal];
        [self.backBtn setImage:[UIImage imageNamed:kImageArrowLeftWhite] forState:UIControlStateSelected];
        
        [self.backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
        self.backBtn.backgroundColor = [HZ_WHITE_COLOR colorWithAlphaComponent:0.95];
        self.backBtn.layer.masksToBounds = YES;
        self.backBtn.layer.cornerRadius = [self.backBtn.ubo fw:UB_HALF];
        self.backBtn.selected = NO;
        [self addSubview:self.backBtn];
        
        //客服
        self.serviceBtn = [[UIButton alloc] initWithFrame:CGRectOf([self.ubo fx:UB_RIGHT ux:-kSizeMallViewMargin-kImageButtonWidth oy:20],
                                                                     [self.ubo ow:kImageButtonWidth/2 oh:kImageButtonWidth/2])];
        [self.serviceBtn setImage:[UIImage imageNamed:kImageGoodsServiceChatGray] forState:UIControlStateNormal];
        [self.serviceBtn setImage:[UIImage imageNamed:kImageGoodsServiceChatWhite] forState:UIControlStateSelected];
        [self.serviceBtn addTarget:self action:@selector(serviceBtnClick) forControlEvents:UIControlEventTouchUpInside];
        self.serviceBtn.backgroundColor = [HZ_WHITE_COLOR colorWithAlphaComponent:0.95];
        self.serviceBtn.layer.masksToBounds = YES;
        self.serviceBtn.layer.cornerRadius = [self.serviceBtn.ubo fw:UB_HALF];
        self.serviceBtn.selected = NO;
        [self addSubview:self.serviceBtn];
        
        
    }
    return self;
}

- (void)backBtnClick{
    if (self.targetCallerBack) {
        [self.targetCallerBack call];
    }
}

- (void)serviceBtnClick{
    if (self.targetCallerService) {
        [self.targetCallerService call];
    }
}

- (void)mallHomeBackGroundAlphaChange:(CGFloat)alpha{
    self.backgroundColor = [HZ_MALL_MAIN_THEME_PURPLE colorWithAlphaComponent:alpha];
    self.backBtn.backgroundColor = [HZ_WHITE_COLOR colorWithAlphaComponent:0.95*(1-alpha)];
    self.serviceBtn.backgroundColor = [HZ_WHITE_COLOR colorWithAlphaComponent:0.95*(1-alpha)];
    
    if (alpha >= 0.51) {
        self.serviceBtn.selected = YES;
        self.backBtn.selected = YES;
        
    }else if(alpha <= 0.49){
        self.serviceBtn.selected = NO;
        self.backBtn.selected = NO;
        
    }
}
@end
